package com.itheima.bos.service.base.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheima.bos.dao.base.CourierRepository;
import com.itheima.bos.dao.base.FixedRepository;
import com.itheima.bos.dao.base.TakeTimeRepository;
import com.itheima.bos.domain.base.Courier;
import com.itheima.bos.domain.base.FixedArea;
import com.itheima.bos.domain.base.TakeTime;
import com.itheima.bos.service.base.FixedAreaService;
@Service
@Transactional
public class FixedAreaServiceiImpl implements FixedAreaService {
	@Autowired
	private FixedRepository fixedRepository;
	@Override
	public void save(FixedArea model) {
		fixedRepository.save(model);
	}
	@Override
	public Page<FixedArea> findPageData(Specification<FixedArea> specification, Pageable pageable) {
		return fixedRepository.findAll(specification,pageable);
		
		
	}
	@Autowired
	private CourierRepository courierRepository;
	@Autowired
	private TakeTimeRepository takeTimeRepository;
	@Override
	public void associationCourierToFixedArea(FixedArea model, Integer courierId, Integer takeTimeId) {
		
		FixedArea  fixedArea=fixedRepository.findOne(model.getId());
		Courier courier = courierRepository.findOne(courierId);
		TakeTime taketime = takeTimeRepository.findOne(takeTimeId);
		fixedArea.getCouriers().add(courier);
		courier.setTakeTime(taketime);
	}

}
